package FileClass;
/**
import java.io.File;

public class FindFile
{
	private boolean checkFirst = false;//the flag
	private boolean checkAll = false;
	public boolean findFirst(String path, String pattern)
	{
		File[] listOfFiles = new File(path).listFiles();
		if(listOfFiles != null && !checkFirst)
		{
			for(File item:listOfFiles)
			{
				if(item.getPath().toLowerCase().indexOf(pattern.toLowerCase()) != -1)
				{
					checkFirst = true;
					System.out.println(item.toString());
				}
				if(item.isDirectory())
					findFirst(item.getPath(), pattern);
			}
		}
		return checkFirst;
	}
	public boolean findAll(String path, String pattern)
	{
		File[] listOfFiles = new File(path).listFiles();
		if(listOfFiles != null)
		{
			for(File item:listOfFiles)
			{
				if(item.getPath().toLowerCase().indexOf(pattern.toLowerCase()) != -1)
				{
					checkAll = true;
					System.out.println(item.toString());
				}
				if(item.isDirectory())
					findAll(item.getPath(), pattern);
			}
		}
		return checkAll;
	}
	public static void main(String args[])
	{
		FindFile find = new FindFile();
		long start = System.currentTimeMillis();
		System.out.println(find.findFirst("H:\\", "00"));
		long end = System.currentTimeMillis();
		System.out.println("Time to find: " + (float)(end - start)/1000 +"s");
		start = System.currentTimeMillis();
		System.out.println(find.findAll("H:\\", "00"));
		end = System.currentTimeMillis();
		System.out.println("Time to find: " + (float)(end - start)/1000 +"s");
	}
}
*/

import java.io.File;
import java.io.FilenameFilter;

public class findFirst {
	@SuppressWarnings("unused")
	public boolean findFirst(String path, String pattent) {
		File dir = new File(path);
		String[] dirContent = dir.list(new fiter(pattent));
		for (String string : dirContent) {
			System.out.println(string);
		}
		if (dirContent == null)
			return false;
		return true;

	}

	class fiter implements FilenameFilter {
		String file;

		public fiter(String file) {
			this.file = file;
		}

		public String getName(File source) {
			return source.getName();
		}

		@Override
		public boolean accept(File dir, String name) {
			return name.endsWith(file);
		}

	}

	public static void main(String[] args) {
		findFirst f = new findFirst();
		String path = "E:\\IE 11";
		String pattent = ".exe";
		System.out.println(f.findFirst(path, pattent));
	}

}